package yawning.mew.gui.characters.attributes;

import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.JSpinner;

import yawning.mew.gui.tools.CharacterDataSource;
import org.jdesktop.beansbinding.BeanProperty;
import org.jdesktop.beansbinding.AutoBinding;
import org.jdesktop.beansbinding.Bindings;
import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy;
import javax.swing.SpinnerNumberModel;

@SuppressWarnings("serial")
public class MeleeAttributes extends JPanel {
	private CharacterDataSource source; 
	private JSpinner spnHaste;
	private JSpinner spnHit;
	private JSpinner spnCrit;
	private JSpinner spnAP;
	private JSpinner spSpeed;
	private JSpinner spinner;
	private JSpinner spnLowDmg;
	private JSpinner spnTopDmg;
	/**
	 * Create the panel.
	 */
	public MeleeAttributes(CharacterDataSource source) {
		this.source = source;
		setLayout(null);
		JTextPane txtpnDamage = new JTextPane();
		txtpnDamage.setText("Damage:");
		txtpnDamage.setEditable(false);
		txtpnDamage.setBounds(10, 44, 84, 22);
		add(txtpnDamage);
		
		spnLowDmg = new JSpinner();
		spnLowDmg.setModel(new SpinnerNumberModel(new Integer(0), new Integer(0), null, new Integer(1)));
		spnLowDmg.setToolTipText("Low boundary of weapon damage");
		spnLowDmg.setBounds(104, 46, 84, 20);
		add(spnLowDmg);
		
		JTextPane txtpnAttackPower = new JTextPane();
		txtpnAttackPower.setText("Attack Power:");
		txtpnAttackPower.setEditable(false);
		txtpnAttackPower.setBounds(10, 11, 84, 22);
		add(txtpnAttackPower);
		
		spnAP = new JSpinner();
		spnAP.setModel(new SpinnerNumberModel(new Integer(0), new Integer(0), null, new Integer(1)));
		spnAP.setToolTipText("Base attack power");
		spnAP.setBounds(104, 11, 84, 20);
		add(spnAP);
		
		JTextPane txtpnAttackSpeed = new JTextPane();
		txtpnAttackSpeed.setToolTipText("");
		txtpnAttackSpeed.setText("Attack Speed:");
		txtpnAttackSpeed.setEditable(false);
		txtpnAttackSpeed.setBounds(10, 79, 84, 22);
		add(txtpnAttackSpeed);
		
		spSpeed = new JSpinner();
		spSpeed.setModel(new SpinnerNumberModel(new Integer(0), new Integer(0), null, new Integer(1)));
		spSpeed.setToolTipText("Weapon Speed");
		spSpeed.setBounds(104, 79, 84, 20);
		add(spSpeed);
		
		JTextPane textPane = new JTextPane();
		textPane.setText("Haste:");
		textPane.setEditable(false);
		textPane.setBounds(10, 110, 84, 22);
		add(textPane);
		
		JTextPane textPane_4 = new JTextPane();
		textPane_4.setText("Hit:");
		textPane_4.setEditable(false);
		textPane_4.setBounds(10, 143, 84, 22);
		add(textPane_4);
		
		JTextPane textPane_5 = new JTextPane();
		textPane_5.setText("Crit:");
		textPane_5.setEditable(false);
		textPane_5.setBounds(10, 176, 84, 22);
		add(textPane_5);
		
		spnCrit = new JSpinner();
		spnCrit.setModel(new SpinnerNumberModel(new Integer(0), new Integer(0), null, new Integer(1)));
		spnCrit.setToolTipText("Crit rating");
		spnCrit.setBounds(104, 178, 84, 20);
		add(spnCrit);
		
		spnHit = new JSpinner();
		spnHit.setModel(new SpinnerNumberModel(new Integer(0), new Integer(0), null, new Integer(1)));
		spnHit.setToolTipText("Hit rating");
		spnHit.setBounds(104, 145, 84, 20);
		add(spnHit);
		
		spnHaste = new JSpinner();
		spnHaste.setModel(new SpinnerNumberModel(new Integer(0), new Integer(0), null, new Integer(1)));
		spnHaste.setToolTipText("Haste rating");
		spnHaste.setBounds(104, 112, 84, 20);
		add(spnHaste);
		
		JTextPane txtpnExpertise = new JTextPane();
		txtpnExpertise.setText("Expertise:");
		txtpnExpertise.setEditable(false);
		txtpnExpertise.setBounds(10, 209, 84, 22);
		add(txtpnExpertise);
		
		spinner = new JSpinner();
		spinner.setModel(new SpinnerNumberModel(new Integer(0), new Integer(0), null, new Integer(1)));
		spinner.setToolTipText("Expertise Rating");
		spinner.setBounds(104, 211, 84, 20);
		add(spinner);
		
		spnTopDmg = new JSpinner();
		spnTopDmg.setModel(new SpinnerNumberModel(new Integer(0), new Integer(0), null, new Integer(1)));
		spnTopDmg.setToolTipText("Top boundary of weapon damage");
		spnTopDmg.setBounds(198, 46, 82, 20);
		add(spnTopDmg);
		initDataBindings();

	}
	protected void initDataBindings() {
		BeanProperty<CharacterDataSource, Integer> characterDataSourceBeanProperty = BeanProperty.create("toon.rating_AttackPower");
		BeanProperty<JSpinner, Object> jSpinnerBeanProperty = BeanProperty.create("value");
		AutoBinding<CharacterDataSource, Integer, JSpinner, Object> autoBinding = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, source, characterDataSourceBeanProperty, spnAP, jSpinnerBeanProperty, "meleeAP");
		autoBinding.bind();
		//
		BeanProperty<CharacterDataSource, Integer> characterDataSourceBeanProperty_1 = BeanProperty.create("toon.rating_Haste");
		AutoBinding<CharacterDataSource, Integer, JSpinner, Object> autoBinding_1 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, source, characterDataSourceBeanProperty_1, spnHaste, jSpinnerBeanProperty, "meleeHaste");
		autoBinding_1.bind();
		//
		BeanProperty<CharacterDataSource, Integer> characterDataSourceBeanProperty_2 = BeanProperty.create("toon.rating_Hit");
		AutoBinding<CharacterDataSource, Integer, JSpinner, Object> autoBinding_2 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, source, characterDataSourceBeanProperty_2, spnHit, jSpinnerBeanProperty, "meleeHit");
		autoBinding_2.bind();
		//
		BeanProperty<CharacterDataSource, Integer> characterDataSourceBeanProperty_3 = BeanProperty.create("toon.rating_Crit");
		AutoBinding<CharacterDataSource, Integer, JSpinner, Object> autoBinding_3 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, source, characterDataSourceBeanProperty_3, spnCrit, jSpinnerBeanProperty, "meleeCrit");
		autoBinding_3.bind();
		//
		BeanProperty<CharacterDataSource, Integer> characterDataSourceBeanProperty_4 = BeanProperty.create("toon.rating_Expertise");
		AutoBinding<CharacterDataSource, Integer, JSpinner, Object> autoBinding_4 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, source, characterDataSourceBeanProperty_4, spinner, jSpinnerBeanProperty, "meleeExpertise");
		autoBinding_4.bind();
		//
		BeanProperty<CharacterDataSource, Integer> characterDataSourceBeanProperty_7 = BeanProperty.create("toon.DMG_WeaponDamageSpeed");
		AutoBinding<CharacterDataSource, Integer, JSpinner, Object> autoBinding_7 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, source, characterDataSourceBeanProperty_7, spSpeed, jSpinnerBeanProperty, "meleeWSpeed");
		autoBinding_7.bind();
		//
		BeanProperty<CharacterDataSource, Integer> characterDataSourceBeanProperty_5 = BeanProperty.create("toon.DMG_WeaponDamageTop");
		AutoBinding<CharacterDataSource, Integer, JSpinner, Object> autoBinding_6 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, source, characterDataSourceBeanProperty_5, spnLowDmg, jSpinnerBeanProperty, "lowDMG");
		autoBinding_6.bind();
		//
		BeanProperty<CharacterDataSource, Integer> characterDataSourceBeanProperty_6 = BeanProperty.create("toon.DMG_WeaponDamageBottom");
		AutoBinding<CharacterDataSource, Integer, JSpinner, Object> autoBinding_5 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, source, characterDataSourceBeanProperty_6, spnTopDmg, jSpinnerBeanProperty, "dmgTop");
		autoBinding_5.bind();
	}
}
